<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>cos</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="copyf2array.html" title="copyf2array" />
    <link rel="next" href="cosseg.html" title="cosseg" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">cos</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="copyf2array.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="cosseg.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="cos"></a>
      <div class="titlepage"></div>
      <a id="IndexCos" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">cos</span>
        </h2>
        <p>cos — 
      Performs a cosine function.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp95654480"></a>
        <h2>Description</h2>
        <p>
      Returns the cosine of <span class="emphasis"><em>x</em></span> (<span class="emphasis"><em>x</em></span> in radians).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp95656512"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>cos</strong></span>(x) (no rate restriction)</pre>
      </div>
      <div class="refsect1">
        <a id="idp95717264"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the cos opcode. It uses the file <a class="ulink" href="examples/cos.csd" target="_top"><em class="citetitle">cos.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp95718912"></a>
          <p class="title">
            <strong>Example 137. Example of the cos opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;RT audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o cos.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1
icos1     <span class="op">=</span>          <span class="opc">cos</span>(0) <span class="comment">;cosine of 0 is 1</span>
icos2     <span class="op">=</span>          <span class="opc">cos</span>($M_PI_2) <span class="comment">;cosine of pi/2 (1.5707...) is 0</span>
icos3     <span class="op">=</span>          <span class="opc">cos</span>($M_PI) <span class="comment">;cosine of pi (3.1415...) is -1</span>
icos4     <span class="op">=</span>          <span class="opc">cos</span>($M_PI_2 <span class="op">*</span> 3) <span class="comment">;cosine of 3/2pi (4.7123...) is 0</span>
icos5     <span class="op">=</span>          <span class="opc">cos</span>($M_PI <span class="op">*</span> 2) <span class="comment">;cosine of 2pi (6.2831...) is 1</span>
icos6     <span class="op">=</span>          <span class="opc">cos</span>($M_PI <span class="op">*</span> 4) <span class="comment">;cosine of 4pi is also 1 as it is periodically to 2pi</span>
          <span class="opc">print</span>      icos1, icos2, icos3, icos4, icos5, icos6
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2 <span class="comment">;cos used in panning, after an example from Hans Mikelson</span>
aout      <span class="opc">vco2</span>       0.8, 220 <span class="comment">; sawtooth</span>
kpan      <span class="opc">linseg</span>     p4, p3, p5 <span class="comment">;0 = left, 1 = right</span>
kpan      <span class="op">=</span>          kpan<span class="op">*</span>$M_PI_2 <span class="comment">;range 0-1 becomes 0-pi/2</span>
kpanl     <span class="op">=</span>          <span class="opc">cos</span>(kpan)
kpanr     <span class="op">=</span>          <span class="opc">sin</span>(kpan)
          <span class="opc">outs</span>       aout<span class="op">*</span>kpanl, aout<span class="op">*</span>kpanr
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 0
<span class="stamnt">i</span> 2 0 5 0 1 <span class="comment">;move left to right</span>
<span class="stamnt">i</span> 2 6 5 1 0 <span class="comment">;move right to left</span>
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp95722320"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="cosh.html" title="cosh"><em class="citetitle">cosh</em></a>,
      <a class="link" href="cosinv.html" title="cosinv"><em class="citetitle">cosinv</em></a>,
      <a class="link" href="sin.html" title="sin"><em class="citetitle">sin</em></a>,
      <a class="link" href="sinh.html" title="sinh"><em class="citetitle">sinh</em></a>,
      <a class="link" href="sininv.html" title="sininv"><em class="citetitle">sininv</em></a>,
      <a class="link" href="tan.html" title="tan"><em class="citetitle">tan</em></a>,
      <a class="link" href="tanh.html" title="tanh"><em class="citetitle">tanh</em></a>,
      <a class="link" href="taninv.html" title="taninv"><em class="citetitle">taninv</em></a>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="copyf2array.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="cosseg.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">copyf2array </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> cosseg</td>
        </tr>
      </table>
    </div>
  </body>
</html>
